Rendering multiple render passes or textures
You can use a Blit Render Pass to blit multiple Composition Target Render Pass render passes or textures to the screen using a specific material. By default a Blit Render Pass blits only one Composition Target Render Pass or texture.
For example, you can blit multiple render passes to the screen using a specific material to create post-processing effects, such as bloom. See Tutorial: Create a bloom effect.
To render multiple render passes or textures:
- Modify the DefaultBlit material type to support blitting multiple textures:
- In the Library > Materials and Textures > Material Types > DefaultBlit double-click the Fragment Shader to open it in the Shader Source Editor.
TIPIf your project does not contain the DefaultBlit material type, in the Library > Materials and Textures press Alt and right-click Material Types, and select DefaultBlit.
- In the Shader Source Editor add the uniforms that you want the Blit Render Pass to use, modify the shader to use them, and click Save.
For example, to make the shader mix the Texture0 and Texture1 properties using the custom property Weight to weigh between them, replace the contents of the shader file withuniform sampler2D Texture0;
uniform sampler2D Texture1;
uniform mediump float Weight;
varying mediump vec2 vTexCoord;
void main()
{
precision lowp float;
gl_FragColor = mix(texture2D(Texture0, vTexCoord), texture2D(Texture1, vTexCoord), Weight);
}
- In the Library > Materials and Textures > Material Types select the DefaultBlit material type and in the Properties click Sync with Uniforms to create and add the properties you defined in the fragment shader to this material type and the materials that use it.
- In the Create Property Type window click Yes to create the custom property type Weight that you use to weigh between the Texture0 and Texture1 properties, in the Property Type Editor set the Default Value property to 0,5, and click Save.
- In the Library > Materials and Textures > Materials select the DefaultBlitMaterial material,
which uses the DefaultBlit material type that you modified to support multiple textures, and in the Properties set the Blend Mode property to Alpha: Premultiplied.
You set Kanzi to blend the textures that it blits on the screen using this material.
-
In the Library press Alt and right-click Rendering, and select Compose and Blit Pass.
Compose and Blit Pass template contains the render pass structure that enables you to blit to the screen Composition Target Render Pass render passes or textures using a specific material. The template contains these render passes:- Composition Target Render Pass renders itself and its child render passes to a composition target.
- Clear Render Pass clears some or all of the buffers of the current render context. By default the Clear Render Pass in the Compose and Blit Pass template clears the color buffer with transparent black color and the depth buffer with value 1.
For example, to clear the color buffer with a different color, set the Clear Color property to the color that you want to use as the background color of the content that Kanzi renders to the Composition Target Render Pass. - Draw Objects Render Pass allows you to set a Camera node to render a specific object source and to control frustum culling. By default the Draw Objects Render Pass uses the default Camera node to render all nodes in a Scene node.
- Blit Render Pass blits one or more render passes or textures on the screen using a specific material. By default this Blit Render Pass draws on the screen the content rendered by the Composition Target Render Pass.
- In the Project select the Scene node whose content you want to render to a composition target and in the Properties set the Render Pass property to the Compose and Blit Pass.
Kanzi renders the content of that Scene node to a composition target and uses the Compose and Blit Pass > Blit Render Pass to draw the content.
- In the Library > Rendering > Render Passes select the Compose and Blit Pass > Blit Render Pass and in the Properties add and set:
- Texture1 to a texture or a Composition Target Render Pass that you want to use.
For example, add the Texture1 property and set it to a texture resource. - Material to the material that you want the Blit Render Pass to use
For example, set it to the DefaultBlitMaterial material whose fragment shader you edited earlier in this procedure to make the material support mixing two textures. - Weight to the amount that you want to show each texture
To give more weight to Texture0, decrease the value of the Weight property, and to give more weight to Texture1, increase the value.
For example, set it to 0,5 to show the average of the textures set by the Texture0 and Texture1 properties.
See also
Tutorial: Create a bloom effect
Rendering
Using material types
Shaders
Textures
Open topic with navigation